Skip to content

Comments

raises: add missing | metacharacter to is_fully_escaped and unescape#14222

Open
bysiber wants to merge 3 commits intopytest-dev:mainfrom
bysiber:fix-missing-pipe-metacharacter
Open

raises: add missing | metacharacter to is_fully_escaped and unescape#14222
bysiber wants to merge 3 commits intopytest-dev:mainfrom
bysiber:fix-missing-pipe-metacharacter

Conversation

@bysiber
Copy link

@bysiber bysiber commented Feb 20, 2026

is_fully_escaped checks whether a match pattern body (inside ^...$) contains only escaped regex metacharacters, so pytest knows it can treat it as a literal string for diff output. The current metacharacter list is:

metacharacters = "{}()+.*?^$[]"

This is missing |, the regex alternation operator. A pattern like ^foo|bar$ would pass the is_fully_escaped check even though the | makes it a regex alternation rather than a literal. This causes rawmatch to be set to the unescaped value foo|bar, leading to a misleading diff in the failure message.

The unescape function has the same omission in its character class, so \| wouldn't be unescaped even if someone properly escaped it.

This adds | to both the metacharacter list in is_fully_escaped and the character class in unescape.

The pipe character is a regex metacharacter (alternation operator)
but is_fully_escaped did not include it, so a match pattern like
'^foo|bar$' would be wrongly identified as a fully-escaped literal.
This causes rawmatch to be set incorrectly, leading to misleading
diff output on match failure.

Also add | to the unescape function's character class for
consistency.
@The-Compiler
Copy link
Member

Similarly to your other PRs I commented on, could you please add a regression test to catch this issue?

bysiber and others added 2 commits February 20, 2026 15:43
Test that | is recognized as a regex metacharacter, not treated as a
literal. Also verify that unescape handles escaped pipes correctly.
@bysiber
Copy link
Author

bysiber commented Feb 20, 2026

Added a regression test that verifies | is recognized as a regex metacharacter in is_fully_escaped, and that unescape properly handles escaped pipes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants